import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios';
import headerView from './views/HeadView.vue'
import blowView from './views/BlowView.vue'
import blowPreView from './views/BlowPreView.vue'
import userViewReal from './components/UserView-real.vue'

import VueRouter  from 'vue-router'

import { Button } from 'element-ui'
import { Form } from 'element-ui'
import { FormItem } from 'element-ui'
import { Input } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'


// 后台俩组件
import admin_left from './views/admin/admin_left.vue'
import admin_nav from './views/admin/admin_nav.vue'
Vue.component('adminLeft',admin_left);
Vue.component('adminNav',admin_nav);


Vue.prototype.$axios = axios;
Vue.config.productionTip = false;
Vue.component('headerView',headerView);
Vue.component('blowView',blowView);
Vue.component('blowPreView',blowPreView);
Vue.component('userViewReal',userViewReal);

Vue.use(Button);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Input);

Vue.use(VueRouter);

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

//添加以下代码
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


// 全局导入cookie相关的使用
import { setCookie, getCookie, checkCookie, clearCookie } from './cookie.js';
Vue.prototype.$setCookie = setCookie;
Vue.prototype.$getCookie = getCookie;
Vue.prototype.$checkCookie = checkCookie;
Vue.prototype.$clearCookie = clearCookie;


//使用 request.js请求头添加token
axios.interceptors.request.use(
  res => {
      if (res) {
          if (getCookie("token")) {
              console.log("拿到token了")
              res.headers.Authorization = getCookie("token")
          }else if(getCookie("adminToken")){
            console.log("拿到adminToken了")
              res.headers.Authorization = getCookie("adminToken")
          }
          return res;
      }
  },
  err => {
      return Promise.reject(err);
  }
);

// 全局导入cryptoJs来进行加密解密
// 全局导入cookie相关的使用
import { encryptionValue,decryptionValue } from './cryptoJS.js';
Vue.prototype.$encryptionValue = encryptionValue;
Vue.prototype.$decryptionValue = decryptionValue;

